<?php
 /*********************************************\
 |* @author Yannic Schnetz, Mike Waldvogel    *|
 |* @copyright Yannic Schnetz, Mike Waldvogel *|
 |*********************************************|
 |* @since 30.07.2013                         *|
 \*********************************************/

// Session starten
session_start();

$_SERVER['REMOTE_ADDR'] = (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];

// Set Locale zu Deutsch.
setlocale(LC_TIME, 'de_DE');
date_default_timezone_set('Europe/Berlin');

// Fehlerausgabe sperren
if (isset($_GET['debug']) or isset($_GET['d'])) {
    error_reporting(E_ALL);
} else {
    error_reporting(E_USER_ERROR);
}

$path_without_params = explode("&", $_SERVER['REQUEST_URI']);

define("ACTIVE_PATH", $_SERVER['REQUEST_URI']);
define("ACTIVE_PATH_NO_PARAMS", $path_without_params[0]);

// Klassen laden
function __autoload($class) {

    if ($class == "Smarty_Internal_TemplateCompilerBase") {
        return;
    }

    if ($class != 'Smarty') {
        if (file_exists('./libs/' . $class . '.class.php')) {
            require_once ('./libs/' . $class . '.class.php');
        } else {
            trigger_error("Klasse " . $class . " nicht gefunden!", E_USER_ERROR);
        }
    } else {
        if (file_exists('./libs/smarty/Smarty.class.php')) {
            require_once ('./libs/smarty/Smarty.class.php');
        } else {
            trigger_error("Klasse " . $class . " nicht gefunden!", E_USER_ERROR);
        }
    }
}

// Smarty laden
$tpl = new Smarty();

// Konfiguration-Klasse
$CONFIG = new Configuration();

// Database-Klasse
$DB = new Database($CONFIG->get("MYSQLHOST"), $CONFIG->get("MYSQLUSER"), $CONFIG->get("MYSQLPASS"), $CONFIG->get("MYSQLDB"));

// Pfade ans Template
$tpl->assign('ACTIVE_PATH', ACTIVE_PATH);
$tpl->assign('ACTIVE_PATH_NO_PARAMS', ACTIVE_PATH_NO_PARAMS);
$tpl->assign('CONFIG', $CONFIG);
$tpl->assign('PATH', $CONFIG->get('PATH'));

// Posts und Gets escapen
Functions::escape_pg();
?>